package com.groupbuying.store.service.impl;

import com.groupbuying.store.constants.CommonConstants;
import com.groupbuying.store.utils.Query;
import com.groupbuying.store.dao.StoreCheckoutCounterRelDao;
import com.groupbuying.store.domain.StoreCheckoutCounterDO;
import com.groupbuying.store.domain.StoreCheckoutCounterRelDO;
import com.groupbuying.store.dto.forManage.StoreCheckoutCounterRelDTO;
import com.groupbuying.store.pojo.BaseEnum;
import com.groupbuying.store.pojo.StoreCheckoutCounterRelEnum;
import com.groupbuying.store.service.StoreCheckoutCounterRelService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class StoreCheckoutCounterRelServiceImpl implements StoreCheckoutCounterRelService {
    @Autowired
    private StoreCheckoutCounterRelDao storeCheckoutCounterRelDao;

    @Override
    public StoreCheckoutCounterRelDO get(String uuid) {
        return storeCheckoutCounterRelDao.get(uuid);
    }

    @Override
    public List<StoreCheckoutCounterRelDO> list(Map<String, Object> map) {
        return storeCheckoutCounterRelDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return storeCheckoutCounterRelDao.count(map);
    }

    @Override
    public int save(StoreCheckoutCounterRelDO storeCheckoutCounterRel) {


        return storeCheckoutCounterRelDao.save(storeCheckoutCounterRel);
    }

    @Override
    public int update(StoreCheckoutCounterRelDO storeCheckoutCounterRel) {
        return storeCheckoutCounterRelDao.update(storeCheckoutCounterRel);
    }

    @Override
    public int remove(String uuid) {
        return storeCheckoutCounterRelDao.remove(uuid);
    }

    @Override
    public int batchRemove(String[] uuids) {
        return storeCheckoutCounterRelDao.batchRemove(uuids);
    }

    @Override
    public StoreCheckoutCounterRelDO getByAccountUuidAndCounterUuid(String counterUuid, String accountId ,String delflag) {
        Map<String,Object> param = new HashMap<>();
        param.put("delflag",delflag);
        param.put("counteruuid", counterUuid);
        param.put("staffuuid", accountId);

        List<StoreCheckoutCounterRelDO> list = storeCheckoutCounterRelDao.list(param);
        return list!=null&& list.size()>0?list.get(0): null;
    }

    @Override
    public StoreCheckoutCounterRelDO getByAccountUuid(String accountId) {
        Map<String,Object> param = new HashMap<>();
        param.put("delflag", CommonConstants.COMMON_FLAG_UNDEL);
        param.put("staffuuid", accountId);

        List<StoreCheckoutCounterRelDO> list = storeCheckoutCounterRelDao.list(param);
        return list!=null&& list.size()>0?list.get(0): null;
    }

    @Override
    public List<StoreCheckoutCounterRelDO> getListByCounterUuid(String pageShow, String nowPage, String counterUuid) {
        Map relParam = new HashMap();
        relParam.put("counteruuid", counterUuid);
        relParam.put("sort", "createOpeTime");
        if(StringUtils.isNotBlank(nowPage)||StringUtils.isNotBlank(pageShow)){
            relParam.put("offset", Integer.parseInt(nowPage));
            relParam.put("limit", Integer.parseInt(pageShow));
        }
        relParam.put("delflag",CommonConstants.COMMON_FLAG_UNDEL);
        return storeCheckoutCounterRelDao.list(relParam);
    }

    @Override
    public List<StoreCheckoutCounterRelDTO> getListByAccountId(Query query) {
        return storeCheckoutCounterRelDao.getListByAccountId(query);
    }

    @Override
    public int getListCountByAccountId(Query query) {
        return storeCheckoutCounterRelDao.getListCountByAccountId(query);
    }


}
